#include "cfilter.h"
#include <cmath>
#include <complex>

using namespace std;

void CFilter::HighPassFilter(double _radius)
{
    if (_radius < 0)
    {
        _radius = 0;
    }

    double distance;
    int x1 = m_Width / 2;
    int y1 = m_Height / 2;

    for (int x = 0; x < m_Width; x++)
    {
        for (int y = 0; y < m_Height; y++)
        {
            if ((x == (m_Width / 2)) && (y == (m_Height / 2)))
                continue;


            distance = (float) sqrt((double) (x-x1)*(x-x1)+ (double)(y-y1)*(y-y1));

            if (distance < _radius)
            {
                m_FFTData[x][y].im = 0;
                m_FFTData[x][y].re = 0;
            }
        }
    }
}

void CFilter::PhaseModFilter(int _k, int _l)
{
    const double PI = 3.1415926535;
    double sumN = 0;
    double sumM = 0;

    for (int n = 0; n < m_Width; n++)
    {
        for (int m = 0; m < m_Height; m++)
        {
            complex<double> i = complex<double>(0,1);
            complex<double> res = complex<double>(m_FFTData[n][m].re, m_FFTData[n][m].im);
            res *= exp(i * (-n * _k * 2 * PI / (m_Height * 1.0) - m * _l * 2 * PI / (m_Width * 1.0) +(_k + _l) * PI));

            m_FFTData[n][m].re = res.real();
            m_FFTData[n][m].im = res.imag();
        }
    }
}
